package com.lyl.module.controller;

import cn.hutool.json.JSONObject;
import com.dtflys.forest.Forest;
import com.lyl.module.api.service.LoginApiService;
import com.lyl.module.constant.ALIYUN_GLOBAL_VARIABLE;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr.Luo
 * @date 2022-07-21 10:41
 * @desc
 */
@RestController
@RequiredArgsConstructor
public class AliLoginController {
    private final LoginApiService loginApiService;

    @GetMapping("/getLoginQrCode")
    public String getLoginQrCode(){
        return loginApiService.getLoginQrCode();
    }

    @GetMapping("/checkQrCodeState")
    public JSONObject checkQrCodeState(){
        return loginApiService.checkQrCodeState();
    }

    @PostMapping("/refreshToken")
    public void refreshToken(String refreshToken){
        ALIYUN_GLOBAL_VARIABLE.REFRESH_TOKEN = refreshToken;
        Forest.config().setVariableValue("refresh_token",refreshToken);
        loginApiService.refreshToken();
    }
}
